﻿Imports System.IO
Imports System.Xml
Imports System.Threading
' Copyright © Microsoft Corporation.  All Rights Reserved.
' This code released under the terms of the 
' Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

Public Class Workflow1
    Inherits SequentialWorkflowActivity
    Public Sub New()
        MyBase.New()
        InitializeComponent()
    End Sub
#Region "Global Declarations"
    Public workflowProperties As SPWorkflowActivationProperties = _
    New Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties
    Private taskCompleted As Boolean = False
#End Region

#Region "TaskProps"
    Public taskProperties As SPWorkflowTaskProperties = _
        New Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties()

    Public Shared TaskIDProperty As System.Workflow.ComponentModel.DependencyProperty = DependencyProperty.Register("TaskID", GetType(System.Guid), GetType(Microsoft.Samples.SequentialWorkflow.Workflow1))

    <System.ComponentModel.DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)> _
        <System.ComponentModel.BrowsableAttribute(True)> _
            <System.ComponentModel.CategoryAttribute("Misc")> _
                Public Property TaskID() As System.Guid
        Get
            Return CType(MyBase.GetValue(Microsoft.Samples.SequentialWorkflow.Workflow1.TaskIDProperty), System.Guid)

        End Get
        Set(ByVal value As System.Guid)
            MyBase.SetValue(Microsoft.Samples.SequentialWorkflow.Workflow1.TaskIDProperty, value)

        End Set
    End Property


    Public Shared afterTaskPropsProperty As System.Workflow.ComponentModel.DependencyProperty = DependencyProperty.Register("afterTaskProps", GetType(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties), GetType(Microsoft.Samples.SequentialWorkflow.Workflow1))

    <System.ComponentModel.DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)> _
        <System.ComponentModel.BrowsableAttribute(True)> _
            <System.ComponentModel.CategoryAttribute("Misc")> _
                Public Property afterTaskProps() As Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
        Get
            Return CType(MyBase.GetValue(Microsoft.Samples.SequentialWorkflow.Workflow1.afterTaskPropsProperty), Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)

        End Get
        Set(ByVal value As Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)
            MyBase.SetValue(Microsoft.Samples.SequentialWorkflow.Workflow1.afterTaskPropsProperty, value)

        End Set
    End Property
    Public Shared beforeTaskPropsProperty As System.Workflow.ComponentModel.DependencyProperty = DependencyProperty.Register("beforeTaskProps", GetType(Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties), GetType(Microsoft.Samples.SequentialWorkflow.Workflow1))

    <System.ComponentModel.DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)> _
        <System.ComponentModel.BrowsableAttribute(True)> _
            <System.ComponentModel.CategoryAttribute("Misc")> _
                Public Property beforeTaskProps() As Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties
        Get
            Return CType(MyBase.GetValue(Microsoft.Samples.SequentialWorkflow.Workflow1.beforeTaskPropsProperty), Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)

        End Get
        Set(ByVal value As Microsoft.SharePoint.Workflow.SPWorkflowTaskProperties)
            MyBase.SetValue(Microsoft.Samples.SequentialWorkflow.Workflow1.beforeTaskPropsProperty, value)

        End Set
    End Property
#End Region

#Region "Workflow Routines"
    Private Sub onWorkflowActivated1_Invoked(ByVal sender As System.Object, _
    ByVal e As System.Workflow.Activities.ExternalDataEventArgs)
        Try
            'Startup operations can go here
        Catch ex As Exception
            Dim s As String
            s = ex.Message
        End Try
    End Sub

    Private Sub TaskCreation(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            'Task must have a guid
            TaskID = Guid.NewGuid()
            With taskProperties
                'Setting up the basic task properties
                .PercentComplete = 0.0
                .AssignedTo = System.Threading.Thread.CurrentPrincipal.Identity.Name
                'This is really useful when incorporating InfoPath forms
                .TaskType = 0
                .DueDate = DateTime.Now.AddDays(7)
                .StartDate = DateTime.Now()
                .Title = "SharePoint Workflow Task"
            End With
        Catch ex As Exception

        End Try
    End Sub

    Private Sub CompleteTask(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub onTaskChanged(ByVal sender As System.Object, ByVal e As System.Workflow.Activities.ExternalDataEventArgs)
        'Checking the task properties after the change.
        'Looking for 1.0 to reflect a completed task.
        If afterTaskProps.PercentComplete = 1.0 Then
            taskCompleted = True
        End If
    End Sub
    'This procedure evaluates False when the task has been changed to 100% complete
    Private Sub notCompleted(ByVal sender As System.Object, ByVal e As System.Workflow.Activities.ConditionalEventArgs)
        'The result must be 1.0 for the task to be complete
        e.Result = Not taskCompleted
    End Sub
#End Region

End Class



